package vp.remedies.dr.home.activity;

import java.io.IOException;

import vp.remedies.dr.home.R;
import vp.remedies.dr.home.db.AndroidSQLiteHelper;
import vp.remedies.dr.home.utils.Constantce;
import vp.remedies.dr.home.utils.Utility;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;


public class SplashScreenActivity extends Activity {

	private static int SPLASH_TIME_OUT = 3000;
	
	private Activity activity;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/*
		 * A blank LinearLayout is explicitly set as the content view for this
		 * Activity because no layout is to be mapped on this activity until all
		 * the StartUpTasks are executed. By calling super.onCreate(), the
		 * launcher activity layout will be set on this activity, hence
		 * overriding the same.The layout mapping for this activity is done only
		 * after all the startup tasks are executed.
		 */
		setContentView(R.layout.activity_splash);
		activity = this;
	}

	@Override
	protected final void onResume() {
		super.onResume();
		// Execute the startup tasks
		Log.i("test", "onResume");
		int dbVersionRes = Constantce.DATABASE_VERSION;
		try {
			AndroidSQLiteHelper.setInstance(new AndroidSQLiteHelper(this,dbVersionRes));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		new Handler().postDelayed(new Runnable() {
			 
            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */
 
            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Utility.startNewActivity(activity, MainActivity.class);
 
                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
		
	}

}
